/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.nhncorp.neptune.examples.first;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.nhncorp.neptune.client.AsyncDataReceiver;
import com.nhncorp.neptune.client.Cell;
import com.nhncorp.neptune.client.CellFilter;
import com.nhncorp.neptune.client.NTable;
import com.nhncorp.neptune.client.Row;
import com.nhncorp.neptune.common.conf.NConfiguration;
import com.nhncorp.neptune.tablet.TableSchema;

public class ParallelGet {
  public static void main(String[] args) throws IOException {
    //테이블 생성 및 데이터 입력
    String tableName = "SimpleTable2";
    String[] columns = new String[]{"Column1", "Column2"};
    String description = "테스트";
    TableSchema tableSchema = new TableSchema(tableName, description, columns);
    
    NConfiguration nconf = new NConfiguration();
    NTable.createTable(nconf, tableSchema);
    
    NTable ntable = NTable.openTable(nconf, tableName);
    
    List<Row.Key> rowKeys = new ArrayList<Row.Key>();
    for(int i = 0; i < 100; i++) {
      Row.Key rowKey = new Row.Key(String.valueOf(i));
      Row row = new Row(rowKey);
      
      row.addCell("Column1", new Cell(Cell.Key.EMPTY_KEY, String.valueOf(i).getBytes()));
    }
    
    List<CellFilter> cellFilters = new ArrayList<CellFilter>();
    cellFilters.add(new CellFilter("Column1"));
    ntable.get(rowKeys, cellFilters, new DataReceiver(), 10, 20);
  }
  
  static class DataReceiver implements AsyncDataReceiver {
    List<Row> results = new ArrayList<Row>();
    @Override
    public void error(Row.Key rowKey, Exception exception) {
      System.out.println("Error:" + rowKey);
    }

    @Override
    public void receive(Row.Key rowKey, Row row) throws IOException {
      results.add(row);
    }

    @Override
    public void timeout() {
    }
  }
}
